let IDX = 256, HEX = []
while(IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1)

/**
 * const toID = hexId();
 * // length = 16 (default)
 * toID(); //=> '52032fedb951da00'
 * toID(); //=> '52032fedb951da01'
 * toID(); //=> '52032fedb951da02'
 *
 * // customize length
 * hexId(25)(); //=> '065359875047c63a037200e00'
 * hexId(32)(); //=> 'ca8e4aec7f139d94fcab9cab2eb89f00'
 * hexId(48)(); //=> 'c19a4deb5cdeca68534930e67bd0a2f4ed45988724d8d200'
 * @param len
 * @return {function()}
 */
export function hexId(len = 16) {
  let str = '', num = 0
  return function() {
    if(!str || num === 256) {
      str = ''
      num = (1 + len) / 2 | 0
      while(num--) str += HEX[256 * Math.random() | 0]
      str = str.substring(num = 0, len - 2)
    }
    return str + HEX[num++]
  }
}
